using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LayoutConfiguration : HOConfigurationReader
{
	public TextAsset table;

	protected Dictionary<LayoutInfoKey, LayoutInfo> mCardDictionary = new Dictionary<LayoutInfoKey, LayoutInfo>();

	public static LayoutConfiguration instance
	{
		get;
		private set;
	}

	public static Dictionary<LayoutInfoKey, LayoutInfo> cardDictionary => instance.mCardDictionary;

	public LayoutInfo this[string index]
	{
		get
		{
			LayoutInfoKey keyFromString = GetKeyFromString(index);
			if (mCardDictionary.ContainsKey(keyFromString))
			{
				return mCardDictionary[keyFromString];
			}
			return null;
		}
	}

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
			Read();
		}
		else
		{
			UnityEngine.Object.Destroy(this);
		}
	}

	public void OnApplicationQuit()
	{
		instance = null;
	}

	private void Read()
	{
		Hashtable hashtable = new Hashtable();
		ParseData(table, hashtable);
		IDictionaryEnumerator enumerator = hashtable.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator.Current;
				LayoutInfo layoutInfo = new LayoutInfo();
				LayoutInfoKey layoutInfoKey = new LayoutInfoKey();
				Hashtable hashtable2 = (Hashtable)dictionaryEntry.Value;
				layoutInfo.Chapter = HOConfigurationReader.ParseTableValueToInt(hashtable2["Chapter"]);
				layoutInfoKey.Chapter = layoutInfo.Chapter;
				layoutInfo.Level = HOConfigurationReader.ParseTableValueToInt(hashtable2["Level"]);
				layoutInfoKey.Level = layoutInfo.Level;
				layoutInfo.Star1 = HOConfigurationReader.ParseTableValueToInt(hashtable2["Star1"]);
				layoutInfo.Star2 = HOConfigurationReader.ParseTableValueToInt(hashtable2["Star2"]);
				layoutInfo.Star3 = HOConfigurationReader.ParseTableValueToInt(hashtable2["Star3"]);
				layoutInfo.OpenStar = HOConfigurationReader.ParseTableValueToInt(hashtable2["OpenStar"]);
				layoutInfo.Cost = HOConfigurationReader.ParseTableValueToInt(hashtable2["Cost"]);
				layoutInfo.PhysicalStrengh = HOConfigurationReader.ParseTableValueToInt(hashtable2["PhysicalStrength"]);
				mCardDictionary.Add(layoutInfoKey, layoutInfo);
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
	}

	public static LayoutInfoKey GetKeyFromString(string s)
	{
		string[] array = s.Split('-');
		if (array.Length == 2)
		{
			return LayoutInfoKey.GenerateKey(int.Parse(array[0]), int.Parse(array[1]));
		}
		return null;
	}
}
